package Demo03;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—05—22
 * Time: 12:08
 */
class Person {
    public String dz;

    public Person(String dz) {
        this.dz = dz;
    }

    @Override
    public String toString() {
        return "Person{" +
                "dz='" + dz + '\'' +
                '}';
    }
   /* @Override
    public boolean equals(Object obj) {
        //判断当前obj参数是否为null
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        //不是Person类对象
        if (!(obj instanceof Person)) {
            return false;
        }
        Person ret = (Person) obj;
        return this.dz.equals(ret.dz);
    }*/
/*    @Override
    public int hashCode() {
        return Objects.hash(dz);
    }*/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        Person person = (Person) o;
        return Objects.equals(dz, person.dz);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dz);
    }
}

class Student {

}
public class Test03 {
/*    public static void func(Object o) {
        String str = o.toString();
        System.out.println(str);

    }*/
public static void main(String[] args) {
    Person person = new Person("beijing");
    Person person1 = new Person("beijing");
    System.out.println(person.hashCode());
    System.out.println(person1.hashCode());
}
/*    public static void main4(String[] args) {
        Person person = new Person("beijing");
        Person person1 = person;
        System.out.println(person.equals(person1));
    }*/
/*    public static void main3(String[] args) {
        Person person = new Person("beijing");
        Person person1 = new Person("beijing");
       // System.out.println(person == person1);
        System.out.println(person.equals(null));
*//*        func(new Person());//动态绑定
        func(new Student());*//*
    }*/
/*    public static void main1(String[] args) {
        Object o = new Person();
        Object o2 = new Student();
    }*/
}
